﻿using UnityEngine;
using System.Collections;
using System.Text;

public class Util : MonoBehaviour {

    public static void RotateX(ref Vector3 v, float angle)
    {

        float sin = Mathf.Sin(angle);

        float cos = Mathf.Cos(angle);



        float ty = v.y;

        float tz = v.z;

        v.y = (cos * ty) - (sin * tz);

        v.z = (cos * tz) + (sin * ty);

    }



    public static void RotateY(ref Vector3 v, float angle)
    {

        float sin = Mathf.Sin(angle);

        float cos = Mathf.Cos(angle);



        float tx = v.x;

        float tz = v.z;

        v.x = (cos * tx) + (sin * tz);

        v.z = (cos * tz) - (sin * tx);

    }



    public static void RotateZ(ref Vector3 v, float angle)
    {

        float sin = Mathf.Sin(angle);

        float cos = Mathf.Cos(angle);



        float tx = v.x;

        float ty = v.y;

        v.x = (cos * tx) - (sin * ty);

        v.y = (cos * ty) + (sin * tx);

    }
}

public static class StringExtensions
{
    public static string ReplaceAt(this string orig, int where, int length, string rep)
    {
        StringBuilder sb = new StringBuilder(orig);
        sb.Remove(where, length).Insert(where, rep);
        return sb.ToString();
    }

    public static string ReplaceAt(this string orig, int where, char rep)
    {
        StringBuilder sb = new StringBuilder(orig);
        sb.Remove(where, 1).Insert(where, rep);
        return sb.ToString();
    }
}